package demo.standard;

import java.util.ArrayList;
import java.util.List;

public class NonLeafNode implements INode {
    private List<INode> children = new ArrayList<>();

    private String name;

    public NonLeafNode() {
    }

    public NonLeafNode(String name) {
        this.name = name;
    }

    @Override
    public void use() {
        System.out.println("使用非叶子节点：" + name);
        for (INode child : children) {
            child.use();
        }
    }


    @Override
    public void addChild(INode child) {
        children.add(child);
    }

    @Override
    public void removeChild(INode child) {
        children.remove(child);
    }

    @Override
    public INode getChild(int index) {
        return children.get(index);
    }
}
